package com.molichuxing.gateway.bff.permission.convertor;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.CollectionUtils;
import com.molichuxing.gateway.bff.goods.response.GoodsVo;
import com.molichuxing.gateway.bff.permission.entity.request.*;
import com.molichuxing.gateway.bff.permission.entity.response.*;
import com.molichuxing.services.business.dto.response.GoodsBizBizDto;
import com.molichuxing.services.infrastructure.dto.response.IovGroupDto;
import com.molichuxing.services.infrastructure.dto.response.IovResourceDto;
import com.molichuxing.services.infrastructure.dto.response.request.create.OperationLogCreateDto;
import com.molichuxing.services.infrastructure.dto.response.response.*;
import com.molichuxing.services.property.GroupSystemTypeEnum;
import com.molichuxing.services.property.SystemTypeEnum;
import org.springframework.beans.BeanUtils;

import com.molichuxing.gateway.utils.entity.UserEntity;
import com.molichuxing.services.business.dto.response.AccountLoginBizDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Convert {

	public static UserEntity toUserEntity(AccountLoginBizDto beanBizDto) {
		UserEntity entity = null;
		if (beanBizDto != null) {
			entity = new UserEntity();
			BeanUtils.copyProperties(beanBizDto, entity);
		}
		return entity;
	}

	public static AccountLoginVo toAccountLoginVo(AccountLoginBizDto beanBizDto) {
		AccountLoginVo beanVo = null;
		if (beanBizDto != null) {
			beanVo = new AccountLoginVo();
			BeanUtils.copyProperties(beanBizDto, beanVo);
		}
		return beanVo;
	}

	public static OperationLogCreateDto toOperationLogCreateDto(OperationLogCreateVo createVo) {
		OperationLogCreateDto entity = null;
		if (createVo != null) {
			entity = new OperationLogCreateDto();
			BeanUtils.copyProperties(createVo, entity);
		}
		return entity;
	}


	public static Paged<OperationLogVo> toOperationLogVoPage(Paged<OperationLogDto> page) {
		Paged<OperationLogVo> result = null;;
		if(null != page) {
			result = new Paged<>();
			BeanUtils.copyProperties(page, result);
			result.setList(toOperationLogVoPage(page.getList()));
		}
		return result;
	}

	public static List<OperationLogVo> toOperationLogVoPage(List<OperationLogDto> beanList) {
		List<OperationLogVo> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (OperationLogDto bean : beanList) {
				dtoList.add(toOperationLogVoPage(bean));
			}
		}
		return dtoList;
	}

	public static OperationLogVo toOperationLogVoPage(OperationLogDto bean) {
		OperationLogVo beanDto = null;
		if (bean != null) {
			beanDto = new OperationLogVo();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setGmtCreate(bean.getGmtCreate().toString());
		}
		return beanDto;
	}




    public static Paged<LoginLogVo> toLoginLogVoPage(Paged<LoginLogDto> page) {
        Paged<LoginLogVo> result = null;;
        if(null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setList(toLoginLogVoPage(page.getList()));
        }
        return result;
    }

    public static List<LoginLogVo> toLoginLogVoPage(List<LoginLogDto> beanList) {
        List<LoginLogVo> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (LoginLogDto bean : beanList) {
                dtoList.add(toLoginLogVoPage(bean));
            }
        }
        return dtoList;
    }

    public static LoginLogVo toLoginLogVoPage(LoginLogDto bean) {
        LoginLogVo beanDto = null;
        if (bean != null) {
            beanDto = new LoginLogVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setLoginTime(bean.getLoginTime().toString());
        }
        return beanDto;
    }

	public static AccountVo toAccountVo(AccountDto beanDto) {
		AccountVo beanVo = null;
		if (beanDto != null) {
			beanVo = new AccountVo();
			BeanUtils.copyProperties(beanDto, beanVo);

			beanVo.setIsSuper(beanDto.getIsSuper() ? 1 : 0);
			beanVo.setSmartTerminal(beanDto.getSmartTerminal() ? 1 : 0);
		}
		return beanVo;
	}

	public static AccountDto toAccountDto(AccountVo vo) {
		AccountDto dto = null;
		if (vo != null) {
			dto = new AccountDto();
			BeanUtils.copyProperties(vo, dto);
		}
		return dto;
	}

	public static List<GroupVo> toGroupVoList(List<GroupDto> dtoList) {
		List<GroupVo> result = null;
		if (CollectionUtils.isNotEmpty(dtoList)) {
			result = new ArrayList<>();
			for (GroupDto dto : dtoList) {
				result.add(toGroupVo(dto));
			}
		}
		return result;
	}

	public static GroupVo toGroupVo(GroupDto dto) {
		GroupVo vo = null;
		if (dto != null) {
			vo = new GroupVo();
			BeanUtils.copyProperties(dto, vo);
			if (dto.getGroupSystemType() != null) {
				vo.setGroupSystemType(dto.getGroupSystemType().getValue());
				vo.setSystemTypeStr(dto.getGroupSystemType().getName());
			}
		}
		return vo;
	}

	public  static GroupDto toGroupDto(GroupVo vo) {
		GroupDto dto = null;
		if (vo != null) {
			dto = new GroupDto();
			BeanUtils.copyProperties(vo, dto);
			if (vo.getGroupSystemType() != null)
				dto.setGroupSystemType(GroupSystemTypeEnum.getEnum(vo.getGroupSystemType()));
		}
		return dto;
	}

	public static AccountCreateDto toAccountCreateDto(AccountCreateVo vo) {
		AccountCreateDto dto = null;
		if (vo != null) {
			dto = new AccountCreateDto();
			BeanUtils.copyProperties(vo, dto);
			dto.setSystemType(SystemTypeEnum.DEALER.getValue());
			if (vo.getSmartTerminal() == 1) {
				dto.setSmartTerminal(true);
			}
		}
		return dto;
	}

	public static AccountModifyDto toAccountModifyDto(AccountModifyVo vo) {
		AccountModifyDto dto = null;
		if (vo != null) {
			dto = new AccountModifyDto();
			BeanUtils.copyProperties(vo, dto);
			if (vo.getSmartTerminal() == 1) {
				dto.setSmartTerminal(true);
			}
		}
		return dto;
	}

	public static GroupCreateDto toGroupCreateDto(GroupCreateVo vo) {
		GroupCreateDto dto = null;
		if (vo != null) {
			dto = new GroupCreateDto();
			BeanUtils.copyProperties(vo, dto);
			dto.setGroupSystemType(GroupSystemTypeEnum.DEALER.getValue());
		}
		return dto;
	}

	public static GroupModifyDto toGroupModifyDto(GroupModifyVo vo) {
		GroupModifyDto dto = null;
		if (vo != null) {
			dto = new GroupModifyDto();
			BeanUtils.copyProperties(vo, dto);
			dto.setGroupSystemType(GroupSystemTypeEnum.DEALER.getValue());
		}
		return dto;
	}


	public static  List<ResourceDto> toResourceDtoList(List<IovResourceDto> dtos) {
		List<ResourceDto> vos = null;
		if (CollectionUtils.isNotEmpty(dtos)) {
			vos = new ArrayList<>();
			for (IovResourceDto dto : dtos) {
				vos.add(toResourceDto(dto));
			}
		}
		return vos;
	}

	public static ResourceDto toResourceDto(IovResourceDto dto) {
		ResourceDto vo = null;
		if (dto != null) {
			vo = new ResourceDto();
			BeanUtils.copyProperties(dto, vo);
		}
		return vo;
	}
}
